package cn.cxd.leetcode;

import java.util.Arrays;

public class Leetcode260 {

    public int[] singleNumber(int[] nums) {
        int[] res = new int[2];
        int index = 0;
        Arrays.sort(nums);
        for (int i = 0; i < nums.length; i++) {
            if (i == 0) {
                if (nums[i] != nums[i + 1]) {
                    res[index] = nums[i];
                    ++index;
                }
            } else if (i == nums.length - 1) {
                if (nums[i] != nums[i - 1]) {
                    res[index] = nums[i];
                    ++index;
                }
            } else {
                int left = nums[i - 1];
                int curr = nums[i];
                int right = nums[i + 1];
                if (curr != left && curr != right) {
                    res[index] = nums[i];
                    ++index;
                }
            }
        }
        return res;
    }
}
